/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package speedymarket_fusion;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import java.sql.SQLException;

/**
 *
 * @author groupspeedymarket_fusion
 */
public class SpeedyMarketAccessDB {

    private Dao<Article, Integer> articleDao;
    private Dao<Marque, Integer> marqueDao;
    private Dao<Categorie, Integer> categorieDao;
    private Dao<Image, Integer> imageDao;
    private Dao<Type_TVA, Integer> type_tvaDao;
    private static SpeedyMarketAccessDB unspeedymarketaccessDB;
    private static String databaseURL;
    private static ConnectionSource connexion;

    SpeedyMarketAccessDB() throws SQLException {

        /*databaseURL = "jdbc:mysql://83.173.65.27/tpdevlog2014g2";
        connexion = new JdbcConnectionSource(databaseURL);
        ((JdbcConnectionSource) connexion).setUsername("tpdevlog2014g2");
        ((JdbcConnectionSource) connexion).setPassword("g7364*");*/
        databaseURL = "jdbc:mysql://192.168.29.10/speedymarketclass";
        connexion = new JdbcConnectionSource(databaseURL);
        ((JdbcConnectionSource) connexion).setUsername("root");
        ((JdbcConnectionSource) connexion).setPassword("Materobi");
        articleDao = DaoManager.createDao(connexion, Article.class);
        marqueDao = DaoManager.createDao(connexion, Marque.class);
        categorieDao = DaoManager.createDao(connexion, Categorie.class);
        imageDao = DaoManager.createDao(connexion, Image.class);
        type_tvaDao = DaoManager.createDao(connexion, Type_TVA.class);

    }

    public static Dao<Article, Integer> getArticleDao() throws SQLException {
        if (unspeedymarketaccessDB == null) {
            unspeedymarketaccessDB = new SpeedyMarketAccessDB();
        }
        return unspeedymarketaccessDB.articleDao;
    }

    public static Dao<Marque, Integer> getMarqueDao() throws SQLException {

        if (unspeedymarketaccessDB == null) {
            unspeedymarketaccessDB = new SpeedyMarketAccessDB();
        }
        return unspeedymarketaccessDB.marqueDao;
    }

    public static Dao<Categorie, Integer> getCategorieDao() throws SQLException {

        if (unspeedymarketaccessDB == null) {
            unspeedymarketaccessDB = new SpeedyMarketAccessDB();
        }
        return unspeedymarketaccessDB.categorieDao;
    }

    public static Dao<Image, Integer> getImageDao() throws SQLException {

        if (unspeedymarketaccessDB == null) {
            unspeedymarketaccessDB = new SpeedyMarketAccessDB();
        }
        return unspeedymarketaccessDB.imageDao;
    }

    public static Dao<Type_TVA, Integer> getType_TVADao() throws SQLException {

        if (unspeedymarketaccessDB == null) {
            unspeedymarketaccessDB = new SpeedyMarketAccessDB();
        }
        return unspeedymarketaccessDB.type_tvaDao;
    }
    
    
    
    
    

}
